<template>
  <view class="permission-tip" v-if="showTip">
    <view class="tip-content">
      <view class="tip-icon">
        <u-icon name="warning" color="#ff9900" size="24" />
      </view>
      <text class="tip-text">{{ tipText }}</text>
      <button class="tip-btn" @click="hideTip">知道了</button>
    </view>
  </view>
</template>

<script>
/**
 * 权限提示组件
 * @author Wu.Liang
 * @date 2025-01-27
 */

export default {
  name: 'PermissionTip',
  data() {
    return {
      showTip: false,
      tipText: '',
      timer: null
    }
  },
  methods: {
    /**
     * 显示权限提示
     * @param {string} text 提示文本
     * @param {number} duration 显示时长（毫秒）
     */
    showPermissionTip(text, duration = 3000) {
      this.tipText = text
      this.showTip = true
      
      // 清除之前的定时器
      if (this.timer) {
        clearTimeout(this.timer)
      }
      
      // 设置自动隐藏
      this.timer = setTimeout(() => {
        this.hideTip()
      }, duration)
    },
    
    /**
     * 隐藏权限提示
     */
    hideTip() {
      this.showTip = false
      if (this.timer) {
        clearTimeout(this.timer)
        this.timer = null
      }
    }
  },
  
  beforeDestroy() {
    if (this.timer) {
      clearTimeout(this.timer)
    }
  }
}
</script>

<style scoped>
.permission-tip {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tip-content {
  background-color: #fff;
  border-radius: 8px;
  padding: 20px;
  margin: 20px;
  max-width: 300px;
  text-align: center;
}

.tip-icon {
  margin-bottom: 10px;
}

.tip-text {
  font-size: 16px;
  color: #333;
  line-height: 1.5;
  margin-bottom: 15px;
  display: block;
}

.tip-btn {
  background-color: #007aff;
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 8px 16px;
  font-size: 14px;
}
</style> 